import getApiData from "@/services/cpasRequest";
import notify from "devextreme/ui/notify";
import { request } from 'umi';
/**
 * 底稿模板 树
 * @param params 
 */

// 删除阶段
export async function deletePhase(
  jdid: any,
  sjxmbh: any,
  dbname: string,
  user: any
): Promise<any> {
  const res = await request('/cpasApi/draftManage/removeStep', {
    method: 'POST',
    data: {
      dbname: dbname,
      jdid: jdid,
      sjxmbh: sjxmbh,
      user: user
    }
  })
  return Promise.resolve({
    data: res.data,
    success: res.ok,
  });
}

// 获取底稿数量
export async function paperNumber(dbname: string, zcbfid: string, dgnd: string, sjxmbh: string | undefined): Promise<any> {
  const res = await request('/cpasApi/draftManage/getDgCountByNd', {
    method: 'GET',
    params: {
      dbname: dbname,
      dgnd: dgnd,
      distPath: `${sjxmbh}/${zcbfid}`,
    }
  })
  return Promise.resolve({
    data: res.data,
    success: res.ok,
  });
}

// 删除所有内容
export async function deletePhaseContent(dbname: string, zcbfid: string, dgnd: string, sjxmbh: string | undefined): Promise<any> {
  const res = await request('/cpasApi/draftManage/removeDraftByNd', {
    method: 'POST',
    data: {
      dbname: dbname,
      dgnd: dgnd,
      distPath: `${sjxmbh}/${zcbfid}`,
    }
  })
  return Promise.resolve({
    data: res.data,
    success: res.ok,
  });
}

/**
 * 底稿模板 树
 * @param params 
 */
export async function templateTree(templateName: string) {
  const res = await getApiData('tpl.treeList', { templateName });
  return Promise.resolve({
    data: res.data,
    success: res.ok,
  });
}

/**
 * 
 * @returns 
 */
export async function getTplList() {
  const r = await getApiData('pub.mbTypeList', {});
  return Promise.resolve({
    data: r.data,
    success: r.ok,
  });
}

// 新建阶段
export async function newPhase(
  jdmc: any,
  dgnd: any,
  pjdmc: any,
  sjxmbh: any,
  user: string | undefined,
  dbname: any
): Promise<any> {
  const res = await request('/cpasApi/draftManage/createStep', {
    method: 'POST',
    data: {
      jdmc: jdmc,
      dgnd: dgnd,
      pjdmc: pjdmc,
      sjxmbh: sjxmbh,
      user: user,
      dbname: dbname
    }
  })
  return Promise.resolve({
    data: res.data,
    success: res.ok,
  });
}

// 阶段重命名
export async function PhaseName(
  jdid: any,
  sjxmbh: any,
  rename: any,
  dbname: any,
  Guid: string
): Promise<any> {
  const res = await request('/cpasApi/draftManage/stepRename', {
    method: 'POST',
    data: {
      jdid: jdid,
      sjxmbh: sjxmbh,
      rename: rename,
      dbname: dbname,
      Guid: Guid
    }
  })
  return Promise.resolve({
    data: res.data,
    success: res.ok,
  });
}

export interface dgjdMoveNode {
  dbName: string;
  fromData: any;
  toData: any;
  action: string;  //move移动, in 移入
}


// 移动接口阶段
export async function PhaseMobile(
  params: dgjdMoveNode
): Promise<any> {
  const res = await request('/cpasApi/draftManage/adjustTreeNodeMove', {
    method: 'POST',
    data: params
  })
  return Promise.resolve({
    data: res.data,
    success: res.ok,
  });
}